/**
 * 外来人员通用接口方法库
 * @class HTGlobal
 * @constructor 黄涛
 */
var HTGlobal = function(){
	//单位列表
	this.EnterpriseList = [];
	this.ProjectList = [];
	this.picker = mui.PopPicker?new mui.PopPicker():{};
	
	this.apiKey = 'ext';//默认调取外部接口
	
	// this.filePath = mui.baseWApp.serverUrl+'/outsider/general/download/';//上传文件的预览目录
	this.filePath = mui.baseWApp.serverUrl+'/outsider/general/print/';//上传文件的预览目录
	
	this.userType = ['','场站用户','区域专工','管理员'];
	
	//接口地址配置
	this.apiUrl = {
		group:{
			upload:'/outsider/general/upload',//上传接口
			register:'/appUser/register',//注册接口
			login:'/app/login',//用户登录
			enterprise:'/enterprise/list',//获取单位列表
			projectQueryList:'/project/listByEnterprise/',//根据单位获取项目
			registration:'/registration',//登记
			verificationCode:'/sys/general/verificationCode',//发送手机验证码
			projectQueryList:'/project/queryList?enterpriseId=',//根据单位获取项目
			getDictAbout:'/sys/dictItem/getDictDetail?',//获取字典数据
			postUserPact:'/appUserPact/addInfo',//上传签名协议
			isHasAppUser:'/appUser/isHasAppUser',//是否已经有同名同证件同手机用户
			retrievePassword:'/background/retrievePassword',//修改密码
			getAdmissionNotice:'/outsider/app/tbProjectPact/getAdmissionNotice/',//获取入场登记需知
			leave:'/appUser/leave',//确认离场
			findAdmissionNotice:'/app/appUserPact/findAdmissionNotice',//获取入场需知
			isSubmitSafetyCommit:'/outsider/app/appUserPact/isSubmitSaftyCommit',//查询是否提交安全承诺 
			findSaftyCommit:'/outsider/app/appUserPact/findSaftyCommit',
			getSafetyCommit:'outsider/app/tbProjectPact/getSafetyCommit/',
			appUserPactAddInfo:'/outsider/app/appUserPact/addInfo',
			searchEnterprise:'/outsider/app/enterprise/list',
			getProjectByUser:'/insider/app/project/getProjectByUser',//获取外来人员列表
			workUserCount:'/insider/app/backUpAppUser/userCount',//获取外来人员数据总条数
			workUser:'/insider/app/backUpAppUser/workUser',//获取项目外来人员信息
			insiderAppUser:'/insider/app/appUser/getInfo',//外来人员详情
			registrationLeave:'/insider/app/registration/leave',
			appUserAllLeave:'/insider/app/appUser/allLeave',
			getModOrgs:'/sys/general/menuTree',
			getUserInfo:'/user/info',
			getUserScore:'/insider/app/backUpAppUser/score',//获取用户成绩
			getAuthorizeFile:'/insider/app/backUpAppUser/getAuthorizeFile',//获取授权书文件
			getPersonalData:'/insider/app/backUpAppUser/getDetail/',//获取个人资料
		},
		ext:{
			upload:'/outsider/general/upload',//上传接口
			register:'/outsider/app/register',//外部注册接口
			login:'/outsider/app/login',//外部用户登录
			enterprise:'/outsider/app/enterprise/list',//获取单位列表外部
			projectQueryList:'/outsider/app/project/listByEnterprise',//根据单位获取项目外部
			registration:'/outsider/app/registration',//登记外部
			verificationCode:'/outsider/app/sendSms',//发送手机验证码
			getDictAbout:'/sys/dictItem/getDictDetail?',//获取字典数据
			postUserPact:'/outsider/appUserPact/addInfo',//上传签名协议
			isHasAppUser:'/outsider/app/isHasAppUser',//是否已经有同名同证件同手机用户
			retrievePassword:'/outsider/app/retrievePassword',//修改密码
			getAdmissionNotice:'/outsider/app/tbProjectPact/getAdmissionNotice/',//获取入场登记需知
			leave:'/outsider/app/leave',//外部确认离场
			findAdmissionNotice:'/outsider/app/appUserPact/findAdmissionNotice',//获取入场需知
			isSubmitSafetyCommit:'/outsider/app/appUserPact/isSubmitSafetyCommit',//查询是否提交安全承诺 
			findSaftyCommit:'/outsider/app/appUserPact/findSaftyCommit',
			getSafetyCommit:'/outsider/app/tbProjectPact/getSafetyCommit/',
			appUserPactAddInfo:'/outsider/app/appUserPact/addInfo',
			searchEnterprise:'/outsider/app/enterprise/list',
			verificationCode2:'/outsider/app/verificationCode',//注册短信验证码接口
      myCourse:'/outsider/app/course',//我的课程
      exam:'/outsider/app/exam',//考试列表
      videoRecord:'/outsider/app/coursewaresUsers',//视频观看记录
      examDeatil:'/outsider/app/userPaperResult/enterPaper',//考试详情
      answer:'/outsider/app/userPaperResult/answerQuestion',//提交试题答案
      submitPaper:'/outsider/app/userPaperResult/submitPaper',//提交试题
      examAnswer:'/outsider/app/userPaperResult/detail',//试题详情
      project:'/outsider/app/backUpAppUser',//关联项目
      saveProject:'/outsider/app/backUpAppUser/saveInfo',//关联项目
      updateProject:'/outsider/app/backUpAppUser/update',//编辑关联项目
			getModOrgs:'/sys/general/menuTree',
			updateUserPhone:'/appUser/updateUserPhone', //修改用户手机号
			homeGetUserInfo:'/outsider/app/getUserInfo/',//获取项目是否审核
			findSaftyRing:'/outsider/app/appUserPact/findSaftyRing',//获取用户安质环责任书
			getSafetyRing:'/outsider/app/tbProjectPact/getSafetyRing/',//获取安质环责任书信息
			isSubmitSafetyRing:'/outsider/app/appUserPact/isSubmitSafetyRing',//判断用户是否提交安质环责任书接口
			submitSafetyRing:'/outsider/app/appUserPact/submitSafetyRing',//提交安质环责任书接口
			relationProjectDel:'/outsider/app/backUpAppUser/delete/',//删除关联项目
			isSubmitValuesForm:'/outsider/app/appUserPact/isSubmitValuesForm',//判断用户是否提交价值观认同表
			getValuesForm:'/outsider/app/tbProjectPact/getValuesForm/',//获取价值观认可表信息
			submitValuesForm:'/outsider/app/appUserPact/submitValuesForm',//提交价值观认可表
			findValuesForm:'/outsider/app/appUserPact/findValuesForm',//查询用户签署的价值观认同表
			getLastInfo:'/outsider/app/backUpAppUser/getLastInfo/',//获取APP用户上次关联项目的个人资料信息
			appUserPactisSubmit:'/outsider/app/appUserPact/isSubmit',//判断是否手签
      
		}
		
		
	}
}
HTGlobal.prototype.getStatus = function(callBack,oneStepStatus){
	//用于内页的下一步按钮
	var user = this.getOsUser()
	console.log('user',JSON.stringify(user));
	if(!user) return false;
	var daysStatus = user.daysStatus
	var auditStatus = user.auditStatus
	var isTech = user.isTech
	
	if(auditStatus!=3 && !isTech){
		mui.alert('您关联的项目人员信息未经过审核，请联系场站负责人审核，场站操作步骤：关联项目审核->查看->工作人员->待审核人员。')
		return false;
	}
	if(auditStatus!=5 && isTech){
		mui.alert('您关联的项目人员信息未经过审核，请联系场站负责人审核，场站操作步骤：关联项目审核->查看->工作人员->待审核人员。')
		return false;
	}
	
	if(daysStatus){
		plus.nativeUI.showWaiting('请稍后');
		mui.baseWApp.httpRequst("/outsider/app/course/findCourseStatus/" + user.id, {
		}, function(data) {
			plus.nativeUI.closeWaiting()
			if(data.code=='0'){
				if(daysStatus==1){
					if(oneStepStatus){
						//在当前处停止往下执行
						if(typeof(callBack)=='function') callBack()
						return;
					}
					mui.baseWApp.httpRequst("/outsider/app/exam/findExamStatus/" + user.id, {
					}, function(data) {
						if(data.code=='0'){
							if(typeof(callBack)=='function') callBack()
						}else{
							mui.toast(data.msg)
						}
					})
				}else if(daysStatus==2){
					if(typeof(callBack)=='function') callBack()
				}
			}else{
				mui.toast(data.msg)
			}
			
	
		})
		
	}else{
		mui.toast('请先关联项目，并等待通过审核！')
		return false
	}
	return true;
	
}
HTGlobal.prototype.synchronizationUserInfo = function (callBack) {
  //重置缓存用户项目信息
  var Th = this,
    user = Th.getOsUser()
  if (user)
    mui.baseWApp.httpRequst("/outsider/app/getUserInfo/" + user.id, {
    },
      function (data) {
        console.log('1......', JSON.stringify(data))
        if (data.code == '0' && data.data) {
          var D = data.data
          Th.setOsUser({
            enterpriseName: D.enterpriseName,
            currentProjectName: D.currentProjectName,
            currentProjectId: D.currentProjectId,
            enterpriseProjectId: D.enterpriseProjectId,
            daysStatus: D.daysStatus,
            auditStatus: D.auditStatus,
            compellation: D.compellation,
            idCard: D.idCard,
            phone: D.phone,
            isTech: D.isTech
          })
          if (typeof (callBack) == 'function') callBack(data)
        }
      }
    )
  return;
}
HTGlobal.prototype.ellipsis = function(value,num){
	//字符截取
	  if (!value) return ''
	  if (value.length > num) {
		return value.slice(0,num) + '...'
	  }
	  return value
}
HTGlobal.prototype.eventSelectEnterprise = function(data){
	//选择外来单位
	var data = data.detail;
	if(data){
		this.tempForm.enterpriseId = data.enterpriseId;
		this.tempForm.enterpriseName = data.enterpriseName;
		this.tempForm.currentProjectId = '';
		this.tempForm.currentProjectName = '';
	}
	delete this.tempForm;
}
HTGlobal.prototype.enterpriseSearch = function(form){
	//跳转选择外来单位  当前目录在 formal 目录下
	mui.openWindow({
		url:'./searchEnterprise.html',
		id:'./searchEnterprise.html',
		waiting:{
			autoShow:false
		}
	});
	this.tempForm = form;
}
HTGlobal.prototype.getOsUser = function(){
	//获取外部用户已登录信息
	var res = false;
	var user = localStorage.getItem('outUser');
	if(user){
		res = JSON.parse(user);
	}
	return res;
}
HTGlobal.prototype.setOsUser = function(formData){
	/** 修改登录后的用户属性
	 * @method setOsUser
	 * @param {formData} 属性值对象
	 * @return {空} 
	*/
	var getOsUser = this.getOsUser()
	Object.keys(formData).forEach(function(key){
		getOsUser[key] = formData[key]
	})
	localStorage.setItem("outUser", JSON.stringify(getOsUser));
	return;
}
HTGlobal.prototype.outsidersLogout = function(){
		var btnArr = ['确定', '取消'];
		mui.confirm('确认退出吗?', '提示', btnArr, function(e) {
			if(e.index == "0") {
					mui.openWindow({
						url:"../formal/login_ext.html",
						id:"../formal/login_ext.html",
						waiting:{
							 autoShow:false,
						}
					});
					localStorage.clear();
					setTimeout(function(){
						var homeView = plus.webview.getWebviewById("home.html");
							homeView.close("none");
					},500);
					// var wvs=plus.webview.all();
					// for(var i=0;i<wvs.length;i++){
					// 	if(wvs[i].id!='login_ext'){
					// 		plus.webview.close(wvs[i].id);
					// 	}
					// }
					
			}
		});	
}
HTGlobal.prototype.admissionNotice = function(pid,callback){
	var apiAll = this.apiUrl[this.apiKey];
	apiAll.temporary = apiAll.getAdmissionNotice+pid;
	//获取项目入场需知
	this.fetch({},callback,'读取中','temporary','get')
}
HTGlobal.prototype.retrievePassword = function(form,callback){
	//修改密码
	this.fetch(form,callback,false,'retrievePassword','post')
}
HTGlobal.prototype.hasAppUser = function(form,callback){
	//判断是否存在数据
	this.fetch(form,callback,'请稍后','isHasAppUser','post')
}
HTGlobal.prototype.postUserPact = function(form,callback){
	//上传签名协议
	this.fetch(form,callback,'上传中','postUserPact','post')
}
HTGlobal.prototype.register = function(form,callback){
	//注册
	this.fetch(form,callback,'注册中','register','post')
}
HTGlobal.prototype.getDictList=function(form,callback){
	//获取字典数据	
	this.fetch(form,callback,'调取中','getDictAbout','post')
}
HTGlobal.prototype.registration=function(form,callback){
	//登记中
	this.fetch(form,callback,'登记中','registration','post')
}
HTGlobal.prototype.outsidersLogin = function(data,callback){
	//外部app登录	
	this.fetch(data,callback,'登录中','login','post')
}
HTGlobal.prototype.sendMsgCode = function(obj,action){
	//短信验证码接口变更
	var phone = obj.form.phone;
	if(!phone){
		mui.toast('请输入手机号！');
		return false;
	}
	if(!(/^1[3456789]\d{9}$/.test(phone))){
		mui.toast('手机号码输入错误！');
		return false;
	}
	
	//发送验证码 obj 中必须有 btnTxt 属性值，且初始值为按钮的文字提示
	var _t = obj,ms=60;
	if(_t.btnTxt=='发送验证码'){
		this.fetch({phone:phone,username:phone},function(data){
			_t.timer = setInterval(function(){
				_t.btnTxt = ms+'s';
				if(ms<1){
					clearInterval(_t.timer);
					_t.btnTxt = '发送验证码';
				}
				ms--;
			},1000);
			if(data.code=='0'){
				mui.toast('短信已发送请注意查收！');
			}else{
				mui.toast(data.msg);
				//发送遇到错误
				clearInterval(_t.timer);
				_t.btnTxt = '发送验证码';
			}
		},'正在发送',action,'post')
	}
}
HTGlobal.prototype.sendCode = function (obj) {
  var phone = obj.form.phone;
  if (!phone) {
    mui.toast('请输入手机号！');
    return false;
  }
  if (!(/^1[3456789]\d{9}$/.test(phone))) {
    mui.toast('手机号码输入错误！');
    return false;
  }

  //发送验证码 obj 中必须有 btnTxt 属性值，且初始值为按钮的文字提示
  var _t = obj, ms = 60;
  if (_t.btnTxt == '发送验证码') {
    this.fetch({ phone: phone, username: phone }, function (data) {
      _t.timer = setInterval(function () {
        _t.btnTxt = ms + 's';
        if (ms < 1) {
          clearInterval(_t.timer);
          _t.btnTxt = '发送验证码';
        }
        ms--;
      }, 1000);
      if (data.code == '0') {
        mui.toast('短信已发送请注意查收！');
      } else {
        console.log(JSON.stringify(data));
        mui.toast(data.msg);
        //发送遇到错误
        clearInterval(_t.timer);
        _t.btnTxt = '发送验证码';

      }
    }, '正在发送', 'verificationCode', 'post')
  }
}
HTGlobal.prototype.checkPwd = function(str){
	//验证密码复杂度
	var arr=[];
	// 是数字
	var isDigit = /^.*[0-9]+.*/;
	if(isDigit.test(str)){
	  arr.push(1);
	}
	// isLowerCase 小写字母
	var isLowerCase = /^.*[a-z]+.*/;
	if(isLowerCase.test(str)){
	  arr.push(2);
	}
	// isUpperCase 大写字母
	var isUpperCase = /^.*[A-Z]+.*/;
	if(isUpperCase.test(str)){
	  arr.push(3);
	}
	// isUpperCase 大写字母
	var isSpace = /\W/;
	if(isSpace.test(str)){
	  arr.push(4);
	}
	return arr.length;		
}
HTGlobal.prototype.checkIdCard=function(idcode){
	//身份证认证
	// 加权因子
	var weight_factor = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
	// 校验码
	var check_code = ['1', '0', 'X' , '9', '8', '7', '6', '5', '4', '3', '2'];

	var code = idcode + "";
	var last = idcode[17];//最后一位

	var seventeen = code.substring(0,17);

	// ISO 7064:1983.MOD 11-2
	// 判断最后一位校验码是否正确
	var arr = seventeen.split("");
	var len = arr.length;
	var num = 0;
	for(var i = 0; i < len; i++){
		num = num + arr[i] * weight_factor[i];
	}
	
	// 获取余数
	var resisue = num%11;
	var last_no = check_code[resisue];

	// 格式的正则
	// 正则思路
	/*
	第一位不可能是0
	第二位到第六位可以是0-9
	第七位到第十位是年份，所以七八位为19或者20
	十一位和十二位是月份，这两位是01-12之间的数值
	十三位和十四位是日期，是从01-31之间的数值
	十五，十六，十七都是数字0-9
	十八位可能是数字0-9，也可能是X
	*/
	var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;

	// 判断格式是否正确
	var format = idcard_patter.test(idcode);

	// 返回验证结果，校验码和格式同时正确才算是合法的身份证号码
	return last === last_no && format ? true : false;
}
HTGlobal.prototype.getProjectForPage = function(F,path,callback){
	
	if((F.areaId && F.stationId && F.hasUnit!=1) ||
	(F.enterpriseId!='' && F.hasUnit==1)){
		callback()
		mui.openWindow({
		  url: path+'.html',
		  id: './changeProject.html',
		  extras: {
			form: F
		  }
		});
	}else{
		mui.toast('请先选择上面的选项！')
	}
}
HTGlobal.prototype.getProjectList=function(form,pageCallback){
	
	/* 获取项目列表 */
	var _this = this,callback=function(Data,Form){
		  _this.picker.setData(Data);
	      _this.picker.show(function(selectItems) {
			var shuju = _this.picker.getSelectedItems(selectItems)[0]
	        Form.currentProjectName = shuju.text;
	        Form.currentProject = shuju.value;
	        Form.currentProjectId = shuju.value;
			Form.enterpriseProjectId = shuju.epid;
			
			if(pageCallback && typeof(pageCallback)=='function')
			pageCallback(shuju)
			
			
			
		  });		
	};
	
	var apiAll = this.apiUrl[this.apiKey];
	var _form = form;
	apiAll.temporary = apiAll.projectQueryList;
	if(form.hasUnit!='0'&&form.enterpriseId==''){
	  mui.toast('请选择所属单位')
	  return
	}
	apiAll.temporary += form.hasUnit!='0' ? '?enterpriseId='+form.enterpriseId+'&hasUnit=1' : '?hasUnit=0&areaId='+_form.areaId+'&stationId='+_form.stationId
	console.log(apiAll.temporary)
	this.fetch({},function(data){
		_this.ProjectList = [];
		if(data.code == '0') {
			if(!Array.isArray(data.data) || data.data.length<1){
				mui.toast('未查询到有对应的关联项目！');
				return;
			}
			$.each(data.data, function(i, v) {
				var temp = {
					value: v.projectId,
					text: v.projectName,
					areaName:v.areaName,
					stationName:v.stationName,
					epid:v.id
				}
				_this.ProjectList.push(temp);
			});
			callback(_this.ProjectList,_form)
		} else {
			mui.toast(data.msg)
		}
		delete apiAll.temporary;
	},'调取中','temporary');
}
HTGlobal.prototype.getEnterpriseList=function(form){
		/* 获取单位 */
		//form为传入的表单对象，其中是需要保存的选择器键值
		var _this = this,callback = function(Data,Form){
			  //调取选择器
			  _this.picker.setData(Data);
			  _this.picker.show(function(selectItems) {
				Form.enterpriseName=_this.picker.getSelectedItems(selectItems)[0].text;
				Form.enterpriseId=_this.picker.getSelectedItems(selectItems)[0].value;
				Form.currentProjectName='';
				Form.currentProject='';
				Form.currentProjectId='';
			  });			
		},handleData=function(data){
			if(data.code == '0') {
				if(!Array.isArray(data.data) || data.data.length<1){
					mui.toast('系统还未添加关联企业！');
					return;
				}
				$.each(data.data, function(i, v) {
					var temp = {
						value: v.id,
						text: v.enterpriseName
					}
					_this.EnterpriseList.push(temp);
				});
				callback(_this.EnterpriseList,form);
			} else {
				mui.toast(data.msg);
			}
		};
		
		if(_this.EnterpriseList.length==0){
			this.fetch(form,handleData,'调取中','enterprise')
		}else{
			callback(_this.EnterpriseList,form);
		}
	}

HTGlobal.prototype.fetch = function(form,callback,msg,apiAction,reType){
	var th = this;
	var apiUrl = th.apiUrl[th.apiKey];
	var type = reType?reType:'';
	if(msg)plus.nativeUI.showWaiting(msg);
	mui.baseWApp.httpRequst(apiUrl[apiAction],form,function(res){
		if(msg)plus.nativeUI.closeWaiting();
		callback(res);
	},function(err,xhr){
		if(msg)plus.nativeUI.closeWaiting();
		try{
			callback(JSON.parse(xhr.responseText));
		}catch(e){
			//TODO handle the exception
			callback({code:6,msg:JSON.stringify(err)});
		}
	},type)
}
/** 调用区域列表
 * @method getArea
 * @for HTGlobal
 * @param{form} form 为当前前端的表单内容
 * @return {空} 
*/ 
HTGlobal.prototype.getArea = function(form,callback){
	var th = this,
	fm=form,
	select = function(data){
		var _data = [];
		data.map(function(ie,ix){
			_data.push({
				value:ie.areaId,
				text:ie.areaName
			})
		})
		th.picker.setData(_data);
		th.picker.show(function(selectItems) {
			fm.areaName = selectItems[0].text
			fm.areaId = selectItems[0].value
			if(typeof(callback)=='function')callback()
		});
	};
	//如果没有存储，就调用接口获取
	if(!th.areaList){
		th.fetch({},function(data){
			if(data.code=='0'&&data.data)
			th.areaList = data.data;
			select(th.areaList)
		},'读取中','getModOrgs','post')
	}else{
		select(th.areaList)
	}
	return;
}
/** 调用场站列表
 * @method getStation
 * @for HTGlobal
 * @param{form} form 为当前前端的表单内容
 * @return {空} 
*/ 
HTGlobal.prototype.getStation = function(form,callback){
	var th = this,
	fm = form;
	if(!th.areaList || !form.areaId){
		mui.toast('请先选择区域！');
		return;
	}else{
		var stationList = th.areaList.filter(function(item){
			return item.areaId==form.areaId
		})
		stationList = stationList[0] ? stationList[0].stationList : [];
		var _data = [];
		stationList.map(function(ie,ix){
			_data.push({
				value:ie.stationId,
				text:ie.stationName
			})
		})
		th.picker.setData(_data);
		th.picker.show(function(selectItems) {
			form.stationId = selectItems[0].value
			form.stationName = selectItems[0].text
			if(typeof(callback)=='function')callback()
		});
	}
}


/**
 * 调用4A认证接口
 */
HTGlobal.prototype.toOAuth = function(callBack){
	var success = callBack||function(){};
	var _htAppConfig = {
		// 4A配置信息 isRelease测试版为0正式版为1
		isRelease:1, // 0测试，1正式
		appID:'NEOM',
		url:mui.baseWApp.serverUrl,
		// clientSecret:'NEOM@20220701t.'
		clientSecret:'NEOM'
	};
					plus.OAuth.toOAuth(
						_htAppConfig.isRelease, 
						_htAppConfig.appID, 
						_htAppConfig.url, 
						_htAppConfig.clientSecret,
						function(result) {
							if(result){
								var data = JSON.parse(result[0])||{};
								if(data.state == '0'){//alert(result);
									plus.nativeUI.showWaiting('登录中...');
									// 处理登录返回信息
									localStorage.setItem('token',data.data.access_token);
									
										// 处理登录返回信息
										localStorage.setItem('neiosToken',data.data.access_token);
										localStorage.setItem('neiosCode',data.data.usercode);
										var resdata = data.data;
										var htapi = new HTGlobal();
										htapi.apiKey = 'group';
										htapi.fetch({},function(result){
											success();
											if(result.code=='0')
											localStorage.setItem('groupUser',JSON.stringify(result.data));
										},false,'getUserInfo')
									
									// 获取现场运维人员接口
									let personParam = {
										userId:localStorage.getItem("neiosCode")
										// userId:'P108383'//场站
										// userId:'P108838'//分公司
										// userId:'P620146'//总部
										// userId:'p183951'
										// userId:'pxmwwzi'
									}
									// 
									mui.ajax('https://neom.cgnpc.com.cn/smartreport-api/neios-server/neios-server/app/common/getUserInfo', {
									   	data: JSON.stringify(personParam),
									   	dataType: 'json', //服务器返回json数据
									   	type:"post", //http请求类型
									    headers: {
											'Content-Type':'application/json',
											"token":localStorage.getItem("neiosToken")
										},
									   	timeout: 6000, 
									   	success: function(data) {
											console.log("kkkkkkkkkkkk:"+JSON.stringify(data))
											if (data.code == 0) {
												localStorage.setItem('neiosUser',JSON.stringify(data.data))
													// localStorage.setItem('neiosUser',"获取用户信息失败")
											} else {
												localStorage.setItem('neiosUser',"获取用户信息失败")
												mui.toast('获取用户信息失败！')
											}
											 setTimeout(function(){
												plus.nativeUI.closeWaiting();
												mui.openWindow({
													url: '../group_home.html',
													id: 'home.html',
													show:{
														aniShow:'none' 
													} 
												});
											 },1000);
									   	},
									   	error: function(xhr) { 
											console.log("OOOOooooooo:"+JSON.stringify(xhr))
									   		mui.toast('获取用户信息失败！')
											localStorage.setItem('neiosUser',"获取用户信息失败")
											 setTimeout(function(){
												plus.nativeUI.closeWaiting();
												mui.openWindow({
													url: '../group_home.html',
													id: 'home.html',
													show:{
														aniShow:'none' 
													} 
												});
											 },1000);
									   	}
									});		
									
									
									// var resdata = data.data;
									// var htapi = new HTGlobal();
									// htapi.apiKey = 'group';
									// htapi.fetch({},function(result){
									// 	success();
									// 	console.log(JSON.stringify(result))
									// 	if(result.code=='0')
									// 	localStorage.setItem('groupUser',JSON.stringify(result.data));
									// },false,'getUserInfo')
									
									
									// setTimeout(function(){
									// 	plus.nativeUI.closeWaiting();
									// 	mui.openWindow({
									// 	  url: '../group_home.html',
									// 	  id: 'home.html',
									// 	  show:{
									// 		  aniShow:'none'
									// 	  }
									// 	});
									// },1000);
									
									
								} else {
									mui.toast(data.msg);
								}
							} else {
								mui.toast('登录认证失败');
							}
						}, 
						function(result) {
							console.log(result)
							mui.toast(result[0]);
						}
					);
}

//调用 NEIOS 4A
function getNeiosToken(callBack){
	var success = callBack||function(){};
	//-------测试START-------
	// var _neiosConfig = {
	// 	isRelease:0, // 0测试，1正式
	// 	appID:'NEIOS',
	// 	url:"https://neios-t/neios-server",
	// 	clientSecret:'NEIOS@20211027'
	// };
	//-------测试END-------
	
	//-------生产START-------
	var _neiosConfig = {
		// 4A配置信息 isRelease测试版为0正式版为1
		isRelease:1, // 0测试，1正式
		appID:'NEOM',
		url:mui.baseWApp.serverUrl,
		clientSecret:'NEOM'
	
	};
	//-------生产END-------

	plus.OAuth.toOAuth(
		_neiosConfig.isRelease, 
		_neiosConfig.appID, 
		_neiosConfig.url, 
		_neiosConfig.clientSecret,
		function(result) {
			console.log("========NEIOS========:"+result)
			if(result){
				var data = JSON.parse(result[0])||{};
				if(data.state == '0'){//alert(result);
				plus.nativeUI.showWaiting('登录中...');
				// 处理登录返回信息
				localStorage.setItem('neiosToken',data.data.access_token);
				localStorage.setItem('neiosCode',data.data.usercode);
				var resdata = data.data;
				var htapi = new HTGlobal();
				htapi.apiKey = 'group';
				htapi.fetch({},function(result){
					success();
					if(result.code=='0')
					localStorage.setItem('groupUser',JSON.stringify(result.data));
				},false,'getUserInfo')

			// 获取现场运维人员接口
			let personParam = {
				userId:localStorage.getItem("neiosCode")
				// userId:'P108383'
				// userId:'P108838'
				// userId:'p183951'
				// userId:'pxmwwzi'
			}
			// 
			mui.ajax('https://neom.cgnpc.com.cn/smartreport-api/neios-server/neios-server/app/common/getUserInfo', {
			   	data: JSON.stringify(personParam),
			   	dataType: 'json', //服务器返回json数据
			   	type:"post", //http请求类型
			    headers: {
					'Content-Type':'application/json',
					"token":localStorage.getItem("neiosToken")
				},
			   	timeout: 6000, 
			   	success: function(data) {
					if (data.code == 0) {
						localStorage.setItem('neiosUser',JSON.stringify(data.data))
							// localStorage.setItem('neiosUser',"获取用户信息失败")
					} else {
						localStorage.setItem('neiosUser',"获取用户信息失败")
						mui.toast('获取用户信息失败！')
					}
					 setTimeout(function(){
						plus.nativeUI.closeWaiting();
						mui.openWindow({
							url: '../group_home.html',
							id: 'home.html',
							show:{
								aniShow:'none' 
							} 
						});
					 },1000);
			   	},
			   	error: function(xhr) { 
					console.log("OOOOooooooo:"+JSON.stringify(xhr))
			   		mui.toast('获取用户信息失败！')
					localStorage.setItem('neiosUser',"获取用户信息失败")
					 setTimeout(function(){
						plus.nativeUI.closeWaiting();
						mui.openWindow({
							url: '../group_home.html',
							id: 'home.html',
							show:{
								aniShow:'none' 
							} 
						});
					 },1000);
			   	}
			});						
			} else {
				mui.toast(data.msg);
			}
		} else {
			mui.toast('登录认证失败');
		}
		}, 
		function(result) {
			console.log(result)
				mui.toast(result[0]);
		});
}

$(document).ready(function(){
	var btns = '.p-btn,.p-btn_1';
	$(btns).bind('touchstart',function(){$(this).css('transform','scale(.9)')}).bind('touchend',function(){$(this).css('transform','scale(1)')})
});